package usermanager;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import usermanager.model.User;

public class Main {

	public static void main(String[] args) {
		
		User user = new User();
		
		ApplicationContext context = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
		SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		Query userQuery = session.createQuery("from User u "
				+ "where u.userId = :id");
		userQuery.setInteger("id", 1);
		
		
		user = (User) userQuery.uniqueResult();
		
		System.out.println(user.getSurname());
		
		user.setSurname("TEST2");
		
		session.getTransaction().commit();
		session.close();
	}
}
